package com.example.shkjdemo

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.orhanobut.logger.Logger

class KeyCodeActivity : AppCompatActivity() {
    private val TAG = "KeyCodeActivity"
    private lateinit var btn_touch: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_key_code)
        btn_touch = findViewById(R.id.btn_touch)

        btn_touch.setOnTouchListener(object : View.OnTouchListener {
            @SuppressLint("ClickableViewAccessibility")
            override fun onTouch(v: View, event: MotionEvent): Boolean {
                when(event.action){
                    MotionEvent.ACTION_DOWN->{
                        Logger.i("$TAG, 按下 v = ${v.id},event = ${event.action}")
                    }

                    MotionEvent.ACTION_MOVE->{
                        Logger.i("$TAG, 移动 v = ${v.id},event = ${event.action}")
                    }

                    MotionEvent.ACTION_UP->{
                        Logger.i("$TAG, 抬起 v = ${v.id},event = ${event.action}")
                    }


                }

                return true
            }

        })
    }


    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {

        Logger.v("onKeyDown...keyCode...$keyCode  event ${event?.action}")
        KeyEvent.ACTION_DOWN
        return super.onKeyDown(keyCode, event)

    }

    override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
        Logger.v("onKeyUp...keyCode...$keyCode  event ${event?.action}")
        return super.onKeyUp(keyCode, event)
    }

    override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
        Logger.v("onKeyLongPress...keyCode...$keyCode  event ${event?.action}")
        return super.onKeyLongPress(keyCode, event)
    }
}
